﻿@using Lavka.Core
@using Lavka.Models
@model IEnumerable<Lavka.Models.Products>
         
@foreach (var item in Model) 
{
    <tr>
        @if (Request.IsAuthenticated)
        {
            <td>
                @Html.ActionLink("Редактировать", "Edit", new {id = item.ProductId}) |
                @Html.ActionLink("Удалить", "Delete", new {id = item.ProductId})
            </td>
            <td></td>
        }            
        <td style="width: 130px; border-right: solid 1px #e3e1e1;">
            @if (!string.IsNullOrEmpty(item.Photo))
            {
                var thumbPath = Path.Combine("~/upload/products/thumbnails/", Path.GetFileName(item.Photo));
                <a href="@Url.Content(item.Photo)" title="@item.Name" class="thickbox">
                    <img src="@Url.Content(thumbPath)" alt="@item.Name" class="small-image" />
                </a>
            }
        </td>
        <td></td>
        <td style="border-right: solid 1px #e3e1e1;">
            @if (!string.IsNullOrEmpty(item.Name))
            {
                @Html.ActionLink(item.Name, "Details", new {id = item.ProductId})
            }
        </td>
        <td></td>
        <td style="border-right: solid 1px #e3e1e1;">
			@item.Reference
        </td>
        <td></td>
        <td style="border-right: solid 1px #e3e1e1;">
			@item.Brands.Name
        </td>
        <td></td>
        <td style="border-right: solid 1px #e3e1e1;">
            @{
                var actionPrice = ActionsHelper.GetActionPrice(item, new LavkaDbEntities());
                if(actionPrice != null)
                {
                    <div class="menu-action-price">@String.Format("{0:0.00}", item.Price) грн.</div>
                    <div class="table-price">@String.Format("{0:0.00}", actionPrice) грн.</div>
                }
                else
                {
                    <div class="table-price">@String.Format("{0:0.00}", item.Price) грн.</div>
                }
            }
        </td>
        <td></td>
        <td style="text-align: center;">
            @if (!CartHelper.IsProductInCart(item))
            {
                     <div>
                        <a href="@Url.Content("~/Products/AddToCart/"+ item.ProductId)">
                            <img src="@Url.Content("~/Content/images/cart-green.png")" alt="@item.Name"/>
                        </a>
                     </div>
            }
            else
            {
                <div>
                    Добавлен
                </div>
            } 
        </td>
    </tr>
}

<script type="text/javascript">
    $(document).ready(initPopupImage());
</script>